package com.jianyun.jyzs.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.TextPaint;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;


import com.jianyun.jyzs.R;
import com.jianyun.jyzs.activity.EDMessageActivity;
import com.jianyun.jyzs.activity.EngDetialActivity;
import com.jianyun.jyzs.activity.EngineerProjectDetialActivity;
import com.jianyun.jyzs.activity.OthersDyamicActivity;
import com.jianyun.jyzs.activity.PersonalDyamicActivity;
import com.jianyun.jyzs.bean.BaseResult;
import com.jianyun.jyzs.bean.EngProjectLocResult;
import com.jianyun.jyzs.bean.EngineerProjectResult;
import com.jianyun.jyzs.bean.EngineeringResult;
import com.jianyun.jyzs.constant.SysConstant;
import com.jianyun.jyzs.dao.EngineerDao;
import com.jianyun.jyzs.http.Api;
import com.jianyun.jyzs.http.CustomCallback;
import com.jianyun.jyzs.http.EngineerHttpHelper;
import com.jianyun.jyzs.http.RetrofitHelper;
import com.jianyun.jyzs.utils.DateTime;
import com.jianyun.jyzs.utils.DensityUtil;
import com.jianyun.jyzs.utils.LocalSp;
import com.jianyun.jyzs.utils.LoginCache;
import com.jianyun.jyzs.utils.TextUtil;
import com.jianyun.jyzs.widget.CircleMovementMethod;
import com.jianyun.jyzs.widget.ExpandGridView;
import com.jianyun.jyzs.widget.LineBreakLayout;
import com.jianyun.jyzs.widget.PasteEditText;
import com.jianyun.jyzs.widget.PromptDialog;
import com.jianyun.jyzs.widget.SpannableClickable;
import com.jianyun.jyzs.widget.WaveViewBySinCos2;
import com.jrmf360.rylib.common.util.ToastUtil;

import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

import com.jianyun.jyzs.utils.RceLog;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * 工程动态列表adapter
 * Created by mlli on 2017/10/26.
 */

public class EngineerRecyAdapter extends RecyclerView.Adapter {

    private Activity context;
    public List<EngineeringResult.EngineerBean> mDatas = new ArrayList<>();
    private Gson gson;
    private LinearLayout llDiscussLinear;
    private PasteEditText et_sendmessage;
    private final EngineerDao dao;
    public String setUserid;
    public String enterpriseCode;
    private EngineerProjectResult.EngProject project;
    private EngProjectLocResult.EngTypeLocBean locBean;
    private String USERID = LoginCache.getInstance().getUserInfo().getUserId();


    public void setLocBean(EngProjectLocResult.EngTypeLocBean locBean) {
        this.locBean = locBean;
    }

    public void setProject(EngineerProjectResult.EngProject project) {
        this.project = project;
    }

    public EngineerRecyAdapter(Activity context, LinearLayout llDiscussLinear, PasteEditText et_sendmessage) {
        this.context = context;
        this.gson = new Gson();
        this.llDiscussLinear = llDiscussLinear;
        this.et_sendmessage = et_sendmessage;
        dao = new EngineerDao(context);
    }

    public void setList(List<EngineeringResult.EngineerBean> list) {
        if (mDatas.size() > 0) mDatas.clear();
        mDatas.addAll(list);
        EngineeringResult.EngineerBean bean = new EngineeringResult.EngineerBean();
        bean.setHead(true);
        mDatas.add(0, bean);
        notifyDataSetChanged();
    }

    public void clear() {
        EngineeringResult.EngineerBean bean = new EngineeringResult.EngineerBean();
        bean.setHead(true);
        mDatas.add(0, bean);
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return mDatas == null ? 0 : mDatas.size();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == 0) {
            View view = View.inflate(context, R.layout.activity_engineer_head, null);

            return new EngineerHeadHolder(view);
        } else {
            View view = View.inflate(context, R.layout.item_engineer, null);
            return new EngineerHolder(view);
        }

    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return 0;
        } else {
            return 1;
        }
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        EngineeringResult.EngineerBean bean = mDatas.get(position);
        boolean head = bean.isHead();
        if (head) {
            //head
            setEngineerHeadView((EngineerHeadHolder) holder);
        } else {
            setEngineerView((EngineerHolder) holder, position);
        }
    }


    public void notifyMessageList() {
        notifyItemRangeChanged(0, 1);
    }

    //设置头部显示
    private void setEngineerHeadView(EngineerHeadHolder holder) {
        holder.wave.startAnimation();
        //自己的头像
        LoginCache instance = LoginCache.getInstance();
        String portraitUrl = instance.getLoginCache().getErpRootUrl() + instance.getUserDetaileInfo().getIconPaths();
        if (portraitUrl != null) {
            Glide.with(context).load(portraitUrl).into(holder.head);
        }
        holder.head.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                context.startActivityForResult(new Intent(context, PersonalDyamicActivity.class), 111);
            }
        });
        if (project != null) {
            holder.p1.setText(project.getProJectName());
            holder.ll_xm.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    context.startActivity(new Intent(context, EngineerProjectDetialActivity.class).putExtra(SysConstant.msg_key_string1, project.getAutoId() + ""));
                }
            });
        }
        if (locBean != null) {
            holder.p2.setText(locBean.getPosition());
        }

        boolean edNewMsgTag = LocalSp.getInstance().getEdNewMsgTag(USERID);
        if (edNewMsgTag) {
            int count = LocalSp.getInstance().getEdMessageCount();
            holder.ll_msg.setVisibility(View.VISIBLE);
            holder.msgCount.setText(count + "条消息");
            holder.ll_msg.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    LocalSp.getInstance().setEdNewMsgTag(false);
                    LocalSp.getInstance().clearEdMessageCount();
                    context.startActivityForResult(new Intent(context, EDMessageActivity.class), 112);
                }
            });
        } else {
            holder.ll_msg.setVisibility(View.GONE);
        }

    }

    private String wipeStr(String str) {
        String substring = str;
        if (str.endsWith(",")) {
            substring = str.substring(0, str.length() - 1);
        }
        return substring;
    }

    private void setEngineerView(final EngineerHolder holder, final int position) {
        final EngineeringResult.EngineerBean bean = dao.getEngineerByid(mDatas.get(position).getId(), enterpriseCode);
        final String localUserid = LoginCache.getInstance().getUserInfo().getUserId();
        if (bean != null) {
            final EngineerHolder mholder = holder;

            mholder.headName.setText(wipeStr(bean.getUserName()));
            if (TextUtils.isEmpty(bean.getType())) {
                mholder.tvType.setVisibility(View.GONE);
            } else {
                mholder.tvType.setVisibility(View.VISIBLE);
                mholder.tvType.setText(bean.getType());
            }
            mholder.tvText.setText(bean.getTextStr());
            String userId = bean.getUserId();
            mholder.tvProjectName.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    context.startActivity(new Intent(context, EngineerProjectDetialActivity.class).putExtra(SysConstant.msg_key_string1, bean.getProjectId()));
                }
            });
            mholder.tvProjectLoc.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    context.startActivity(new Intent(context, EngineerProjectDetialActivity.class).putExtra(SysConstant.msg_key_string1, bean.getProjectId()));
                }
            });
            mholder.head.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (localUserid.equals(bean.getUserId())) {
                        //自己
                        context.startActivity(new Intent(context, PersonalDyamicActivity.class));
                    } else {
                        context.startActivity(new Intent(context, OthersDyamicActivity.class).putExtra(SysConstant.msg_key_string1, bean.getUserId()));
                    }
                }
            });
            mholder.headName.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (localUserid.equals(bean.getUserId())) {
                        //自己
                        context.startActivity(new Intent(context, PersonalDyamicActivity.class));
                    } else {
                        context.startActivity(new Intent(context, OthersDyamicActivity.class).putExtra(SysConstant.msg_key_string1, bean.getUserId()));
                    }
                }
            });
            mholder.ivAgree.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    EngineerHttpHelper.agree(dao, bean.getProjectId(), bean.getId(), new EngineerHttpHelper.AgreeResult() {
                        @Override
                        public void agreeResult(boolean b, String msg, List<EngineeringResult.EngineerBean.AgressBean> list) {
                            if (b) {
                                setAgressView(mholder.llCBg, mholder.llCAgree, mholder.llAgree, list);
                            } else {
                                ToastUtil.showNoWaitToast(context, msg);
                            }
                        }
                    });
                }
            });
            mholder.ivDiscuss.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    disArgs.put("projectId", bean.getProjectId());
                    disArgs.put("projectProgressId", bean.getId());
                    openKeybord(bean.getUserName());
                }
            });

            String photo = bean.getPhoto();
            String iconUrl = LoginCache.getInstance().getLoginCache().getErpRootUrl() + photo;
            if (iconUrl != null) {
                try {
                    Glide.with(context).load(iconUrl).into(mholder.head);
                } catch (Exception e) {
                    e.printStackTrace();
                    Glide.with(context).load(R.drawable.rc_default_portrait).into(mholder.head);
                }
            }


            Type attachtype = new TypeToken<List<EngineeringResult.EngineerBean.AttachmentBean>>() {
            }.getType();
            Type agresshtype = new TypeToken<List<EngineeringResult.EngineerBean.AgressBean>>() {
            }.getType();
            Type discusstype = new TypeToken<List<EngineeringResult.EngineerBean.DiscussBean>>() {
            }.getType();
            Type images = new TypeToken<ArrayList<String>>() {
            }.getType();
            List<EngineeringResult.EngineerBean.DiscussBean> discusslist = gson.fromJson(bean.getListDisscuss(), discusstype);
            List<EngineeringResult.EngineerBean.AttachmentBean> attachmentlist = gson.fromJson(bean.getListAttachment(), attachtype);
            List<EngineeringResult.EngineerBean.AgressBean> agresslist = gson.fromJson(bean.getListAgress(), agresshtype);
            //评论数 加点赞数多于20变热点
            int hotnum = discusslist.size() + agresslist.size();
            //Log.i("test","hot:"+hotnum);
            if (hotnum >= 20) {
                mholder.tvHot.setVisibility(View.VISIBLE);
            } else {
                mholder.tvHot.setVisibility(View.INVISIBLE);
            }
            ArrayList<String> imageList = gson.fromJson(bean.getListImages(), images);
            String id = bean.getId();
            Log.i("test", "图片：" + imageList.toString() + "\n" + id);
            if (attachmentlist != null && attachmentlist.size() > 0) {
                Log.i("ysj","有图片："+position);
                EngineerAttachGridViewAdapter engineerAttachGridViewAdapter = new EngineerAttachGridViewAdapter(context, attachmentlist, imageList);
                if (attachmentlist.size() == 1) {
                    LinearLayout.LayoutParams lp0 = new LinearLayout.LayoutParams(DensityUtil.dip2px(context, 165), ViewGroup.LayoutParams.WRAP_CONTENT);
                    mholder.attachRecy.setLayoutParams(lp0);
                    mholder.attachRecy.setNumColumns(1);
                } else {
                    LinearLayout.LayoutParams lp0 = new LinearLayout.LayoutParams(DensityUtil.dip2px(context, 246), ViewGroup.LayoutParams.WRAP_CONTENT);
                    mholder.attachRecy.setLayoutParams(lp0);
                    mholder.attachRecy.setNumColumns(3);
                }
                mholder.attachRecy.setAdapter(engineerAttachGridViewAdapter);
                mholder.attachRecy.setVisibility(View.VISIBLE);
            } else {
                Log.i("ysj","没有图片："+position);
                mholder.attachRecy.setVisibility(View.GONE);
            }
            String dt = bean.getDt();
            Long aLong = DateTime.getmillionTime(dt);
            holder.tvTime.setText(DateTime.getFriendlytime(new Date(aLong)));
            String currentUserid = LoginCache.getInstance().getUserInfo().getUserId();
            if (currentUserid.equals(userId)) {
                holder.tvDelete.setVisibility(View.VISIBLE);
                holder.tvDelete.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        //此动态是本人发布 可删除
                        delEngineer(bean.getId(), holder);
                    }
                });
            } else {
                holder.tvDelete.setVisibility(View.GONE);
            }
            mholder.tvProjectName.setText(bean.getProjectName());
            mholder.tvProjectLoc.setText(bean.getPlace() == null ? "" : "." + bean.getPlace());
            mholder.llCBg.setVisibility(View.GONE);//先让评论和点赞去隐藏
            setAgressView(mholder.llCBg, mholder.llCAgree, mholder.llAgree, agresslist);
            setDiscussView(mholder.llCBg, mholder.llDiscuss, discusslist, bean, position);
            mholder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    context.startActivityForResult(new Intent(context, EngDetialActivity.class).putExtra(SysConstant.msg_key_string1, bean.getId()), 111);
                }
            });
        }
    }

    //打开键盘 准备评论参数
    private void openKeybord(String hint) {
        hint = TextUtil.wipeStr(hint);
        llDiscussLinear.setVisibility(View.VISIBLE);
        //设置可获得焦点
        et_sendmessage.setFocusable(true);
        et_sendmessage.setFocusableInTouchMode(true);
        //请求获得焦点
        et_sendmessage.requestFocus();
        et_sendmessage.setHint("回复" + hint + ":");
        //调用系统输入法
        InputMethodManager inputManager = (InputMethodManager) et_sendmessage.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.showSoftInput(et_sendmessage, 0);
    }

    //设置点赞的显示
    private void setAgressView(LinearLayout llCBg, LinearLayout llCAgree, LineBreakLayout llAgree, List<EngineeringResult.EngineerBean.AgressBean> agresslist) {
        if (agresslist.size() > 0) {
            llCBg.setVisibility(View.VISIBLE);
            llCAgree.setVisibility(View.VISIBLE);
            llAgree.removeAllViews();
            int index = 1;
            for (final EngineeringResult.EngineerBean.AgressBean agree : agresslist) {
                TextView textview = null;
                if (index == agresslist.size()) {
                    textview = processTextView((index == 1 ? "  " : "") + wipeStr(agree.getUserName()), R.color.ppdiscuss);
                } else {
                    textview = processTextView((index == 1 ? "  " : "") + wipeStr(agree.getUserName()) + "、", R.color.ppdiscuss);
                }
                textview.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
//                        ToastUtil.showNoWaitToast(context, "进入个人动态详情界面" + agree.getUserName());
                    }
                });
                llAgree.addView(textview);
                index++;
            }
        } else {
            llCAgree.setVisibility(View.GONE);
        }
    }


    //保存评论的参数
    HashMap<String, String> disArgs = new HashMap<>();
    LinearLayout linearLayout;

    //设置评论的显示
    private void setDiscussView(LinearLayout llCBg, LinearLayout llDiscuss, List<EngineeringResult.EngineerBean.DiscussBean> discusslist, final EngineeringResult.EngineerBean bean, int position) {
        if (discusslist.size() == 0) {
            llDiscuss.setVisibility(View.GONE);
        } else {
            llCBg.setVisibility(View.VISIBLE);
            llDiscuss.setVisibility(View.VISIBLE);
            llDiscuss.removeAllViews();
            final CircleMovementMethod circleMovementMethod = new CircleMovementMethod(R.color.ppdiscussselect, R.color.ppdiscussselect);
            for (final EngineeringResult.EngineerBean.DiscussBean eed : discusslist) {
                linearLayout = processLinearLayout();
                TextView textview = null;
                if (eed.getToUserId() == null || TextUtils.isEmpty(eed.getToUserId())) {//对于当前动态的评论
                    SpannableStringBuilder builder = new SpannableStringBuilder();
                    builder.append(setClickableSpan(wipeStr(eed.getFromUserName()), eed.getFromUserId()));
                    builder.append(":" + eed.getTextStr());
                    textview = processTextView(builder, R.color.content1);
                    textview.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (circleMovementMethod.isPassToTv()) {
                                disArgs.put("toUserId", eed.getFromUserId());
                                disArgs.put("toUserName", eed.getFromUserName());
                                disArgs.put("projectId", bean.getProjectId());
                                disArgs.put("projectProgressId", bean.getId());
                                openKeybord(eed.getFromUserName());
                            }
                        }
                    });
                    textview.setMovementMethod(circleMovementMethod);
                    linearLayout.addView(textview);
                } else {//对于某人评论的回应
                    SpannableStringBuilder builder = new SpannableStringBuilder();
                    builder.append(setClickableSpan(wipeStr(eed.getFromUserName()), eed.getFromUserId()));
                    builder.append("  回复 ");
                    builder.append(setClickableSpan(wipeStr(eed.getToUserName()), eed.getToUserId()));
                    builder.append(":" + eed.getTextStr());
                    textview = processTextView(builder, R.color.content1);
                    textview.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (circleMovementMethod.isPassToTv()) {
                                disArgs.put("toUserId", eed.getFromUserId());
                                disArgs.put("toUserName", eed.getFromUserName());
                                disArgs.put("projectId", bean.getProjectId());
                                disArgs.put("projectProgressId", bean.getId());
                                openKeybord(eed.getFromUserName());
                            }
                        }
                    });
                    textview.setMovementMethod(circleMovementMethod);
                    linearLayout.addView(textview);
                }
                llDiscuss.addView(linearLayout);
            }
        }
    }


    //生成评论人显示文本
    private SpannableString setClickableSpan(final String name, final String id) {
        SpannableString subjectSpanText = new SpannableString(name);
        subjectSpanText.setSpan(new SpannableClickable() {
                                    @Override
                                    public void onClick(View widget) {
                                        //点击进入评论人动态界面
                                        ToastUtil.showNoWaitToast(context, "进入个人页面");
//                                        context.startActivity(new Intent(context,ProjectProgressDetailActivity.class).putExtra(SysConstant.msg_key_string1, id));
                                    }

                                    @Override
                                    public void updateDrawState(TextPaint ds) {
                                        super.updateDrawState(ds);
                                        ds.setColor(0xff2869AD);
                                        ds.setUnderlineText(false);
                                    }
                                }, 0, subjectSpanText.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return subjectSpanText;
    }

    public TextView processTextView(String value, int color) {
        TextView tv = new TextView(context);
        tv.setText(value);
        tv.setTextSize(14);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        tv.setLayoutParams(params);
        tv.setTextColor(context.getResources().getColor(color));
        tv.setGravity(Gravity.LEFT | Gravity.CENTER);
        tv.setHighlightColor(context.getResources().getColor(android.R.color.transparent));
//		tv.setId(id);
        return tv;
    }

    public TextView processTextView(SpannableStringBuilder value, int color) {
        TextView tv = new TextView(context);
        tv.setText(value);
        tv.setTextSize(14);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        tv.setLayoutParams(params);
        tv.setTextColor(context.getResources().getColor(color));
        tv.setGravity(Gravity.LEFT | Gravity.CENTER);
        tv.setHighlightColor(context.getResources().getColor(android.R.color.transparent));
        return tv;
    }

    //设置评论的水平布局
    public LinearLayout processLinearLayout() {
        LinearLayout linearLayout = new LinearLayout(context);
        LinearLayout.LayoutParams lp0 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        linearLayout.setOrientation(LinearLayout.HORIZONTAL);
        linearLayout.setLayoutParams(lp0);
        return linearLayout;
    }


    //发出评论消息
    public void sendDiscuss(String text) {
        disArgs.put("text", text);
        EngineerHttpHelper.discuss(dao, disArgs, disArgs.get("projectProgressId"), new EngineerHttpHelper.DiscussResult() {
            @Override
            public void discussResult(boolean b, String msg, List<EngineeringResult.EngineerBean.DiscussBean> list) {
                if (b) {
                    notifyDataSetChanged();
                } else {
                    ToastUtil.showNoWaitToast(context, msg);
                }
            }
        });
    }

    //清除评论参数
    public void clearArgs() {
        disArgs.clear();
    }


    class EngineerHeadHolder extends RecyclerView.ViewHolder {

        private final WaveViewBySinCos2 wave;
        private final TextView p1;
        private final TextView p2;
        private final ImageView head;
        private final LinearLayout ll_xm;
        private final LinearLayout ll_msg;
        private final TextView msgCount;


        public EngineerHeadHolder(View itemView) {
            super(itemView);
            wave = (WaveViewBySinCos2) itemView.findViewById(R.id.wave);
            p1 = (TextView) itemView.findViewById(R.id.p1);
            p2 = (TextView) itemView.findViewById(R.id.p2);
            head = (ImageView) itemView.findViewById(R.id.iv_head);
            ll_xm = (LinearLayout) itemView.findViewById(R.id.linearLayout);
            ll_msg = (LinearLayout) itemView.findViewById(R.id.ll_newMsg);
            msgCount = (TextView) itemView.findViewById(R.id.tv_newMsgCount);
        }
    }

    class EngineerHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.head)
        ImageView head;
        @BindView(R.id.headParent)
        LinearLayout headParent;
        @BindView(R.id.headName)
        TextView headName;
        @BindView(R.id.tv_type)
        TextView tvType;
        @BindView(R.id.tv_text)
        TextView tvText;
        @BindView(R.id.hot)
        TextView tvHot;
        @BindView(R.id.gv_gridView)
        ExpandGridView attachRecy;
        @BindView(R.id.tv_projectName)
        TextView tvProjectName;
        @BindView(R.id.tv_projectLoc)
        TextView tvProjectLoc;
        @BindView(R.id.tv_time)
        TextView tvTime;
        @BindView(R.id.tv_delete)
        TextView tvDelete;
        @BindView(R.id.iv_agree)
        ImageView ivAgree;
        @BindView(R.id.iv_discuss)
        ImageView ivDiscuss;
        @BindView(R.id.ll_agree)
        LineBreakLayout llAgree;
        @BindView(R.id.ll_c_agree)
        LinearLayout llCAgree;
        @BindView(R.id.ll_discuss)
        LinearLayout llDiscuss;
        @BindView(R.id.ll_c_bg)
        LinearLayout llCBg;

        public EngineerHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    private void delEngineer(final String id, final EngineerHolder holder) {
        PromptDialog dialog = PromptDialog.newInstance(context, "确定删除？", "");
        dialog.setPromptButtonClickedListener(new PromptDialog.OnPromptButtonClickedListener() {
            @Override
            public void onPositiveButtonClicked() {
                HashMap<String, String> map = new HashMap<>();
                map.put("method", "deleteProjectProgress");
                map.put("userId", setUserid);
                map.put("enterpriseCode", enterpriseCode);
                map.put("progressId", id);
                map.put("appCode", "jyzs");
                map.put("appType", "Android");
                map.put("appVersion", "1.0.2");
                Log.i("test", "删除参数：" + map.toString());
                Api api = RetrofitHelper.builderCeshiHttp().create(Api.class);
                api.delNewEngineer(map).observeOn(AndroidSchedulers.mainThread())
                        .subscribeOn(Schedulers.io())
                        .subscribe(new CustomCallback<BaseResult>() {
                            @Override
                            protected void onResponse(BaseResult response) {
                                RceLog.i("lml", response.toString());
                                if (response.isResult()) {
                                    //删除成功 移除item 移除本地数据库数据
                                    dao.delEngineer(id);
                                    mDatas.remove(holder.getAdapterPosition());
                                    notifyItemRemoved(holder.getAdapterPosition());
                                } else {
                                    ToastUtil.showNoWaitToast(context, response.getMessage());
                                }
                            }

                            @Override
                            protected void onException(String msg) {
                                ToastUtil.showNoWaitToast(context, msg);
                            }
                        });
            }

            @Override
            public void onNegativeButtonClicked() {

            }
        });
        dialog.show();

    }
}
